<?php
/*
 * Created on 2011-9-26
 *
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 */
 class ModelAnalyzeUsertimeline extends Model{
 	public function getUsertimeline($user_id){
 		$result=$this->db->query("select * from user_timeline where user_id='".$user_id."'");
 		
 		return $result;
 	}
	
	public function analyzeUsertimeline($datas){
	
		$num_original=0;
		$in_reply_count=0;
		$retweet=0;
		foreach($datas as $data){
			if($data['is_retweet']==''){
				$num_original++;
			}
			
			if(isset($data['comments'])){
				$in_reply_count+=$data['comments'];
			}
			
			if(isset($data['rt'])){
				$retweet+=$data['rt'];
			}
		}
		
		$aresult=array();
		$aresult['user_id']=$datas[0]['user_id'];
		$aresult['original_percent']=$num_original/count($datas);
		$aresult['original_influnce']=($in_reply_count+$retweet*2)/count($datas);
		$aresult['original_frequency']='暂无数据';
		$aresult['analyze_time']=Util::getDate();
		
		$this->insert_Usertimelineanalyze($aresult);
	}
	
	public function getLatestAnalyzeDate($user_id){
	
		return $this->db->query("select * from "  . DB_PREFIX . "user_timeline_analyze where user_id='".$user_id."' order by id desc")->row['analyze_time'];
	}
	
	public function insert_Usertimelineanalyze($dataarray){
		$sql='insert into ' . DB_PREFIX . 'user_timeline_analyze SET ';
		$i=0;
		foreach($dataarray as $key => $value){
			if($i==0){
				$sql.=$key."='".$value."' ";
			}else{
				$sql.=", ".$key."='".$value."'";
			}
			$i++;
		}
		$this->log->write($sql);
 		$this->db->query($sql);
	}
 }
?>
